using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using GC2.Bussines;
using GC2.Bussines.BMLogistica;
using GC2.Entities.Logistica;
using GC2.Entities.Seguridad;
using GC2.ExceptionHandler;

public partial class Parametros_PPLogistica : GenericPage
{
    #region Propiedades 
    GC2.Funciones.General.FunctionsSite f = new GC2.Funciones.General.FunctionsSite();
    #endregion

    #region Controles

    #region Page_Load
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            SetearCultura();
            SetearConexion();
            if (!IsPostBack)
            {
                lblAccion.Text = "Actualiza Par&aacute;metro Log&iacute;stica";
                MuestraDatos();
                lblDias.Visible = false;
                lblKm.Visible = false;
                lblDiasLotes.Visible = false;
            }
        }
        catch (Exception ex) { ErrorUI(ex); }
    }
    #endregion

    #region btnGuardar_Click
    protected void btnGuardar_Click(object sender, EventArgs e)
    {
        try
        {
            lblDias.Visible = false;
            lblKm.Visible = false;
            bool bOk = f.isNumeric(txtDias.Text.Trim());
            if (!bOk)
            {
                lblDias.Visible = true;
                lblAccion.Text = "D&iacute;as antes Vto. P&oacute;liza Incorrecto";
                return;
            }
            bOk = f.isNumeric(txtKm.Text.Trim());
            if (!bOk)
            {
                lblKm.Visible = true;
                lblAccion.Text = "Km antes para Mantenimiento Incorrecto";
                return;
            }
            bOk = f.isNumeric(txtDiasLotes.Text.Trim());
            if (!bOk)
            {
                lblDiasLotes.Visible = true;
                lblAccion.Text = "D&iacute;as antes Vto. Lotes Incorrecto";
                return;
            }
            Guardar();
            lblAccion.Text = "Par&aacute;metro Actualizado";
        }
        catch (Exception ex) { ErrorUI(ex); }
    }
    #endregion

    #region btnCancelar_Click
    protected void btnCancelar_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Seguridad/Default.aspx", false);
    }
    #endregion

    #endregion

    #region Metodos
   
    #region MuestraDatos
    protected void MuestraDatos()
    {
        try
        {
            BMPLogistica bmPLogistica = new BMPLogistica(Connection);
            PLogistica pLogistica = bmPLogistica.BMPLogisticaGet();

            txtDias.Text = pLogistica.Dias.ToString();
            txtKm.Text = pLogistica.Km.ToString();
            txtTitulo.Text = pLogistica.Titulo;
            txtDiasLotes.Text = pLogistica.DiasLotes.ToString();
        }
        catch (Exception ex) { ErrorUI(ex); }
    }
    #endregion

    #region Guardar
    protected void Guardar()
    {
        try
        {
            BMPLogistica bmPLogistica = new BMPLogistica(Connection);
            PLogistica pLogistica = new PLogistica();
            pLogistica.Id = 1;
            pLogistica.Dias = int.Parse(txtDias.Text.Trim());
            pLogistica.Km = Int32.Parse(txtKm.Text.Trim());
            pLogistica.Titulo = txtTitulo.Text;
            pLogistica.DiasLotes = int.Parse(txtDiasLotes.Text);
            bmPLogistica.BMPLogisticaUpdate(pLogistica);
        }
        catch (Exception ex) { ErrorUI(ex); }
    }
    #endregion

    #endregion
}
